import request from '@/utils/http';

export const postDietAppUserLogin = (
  data: {
    /** 手机号（登录账号） */
    phone: string;
    /** 密码（6-12位） */
    password: string;
    /** 家属、本人 */
    role: 'PERSON' | 'FAMILY';
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '',
    url: '/diet/app/user/login',
    data,
    ...config,
  });

/** 我的信息 */
export const getDietAppUser = (config?: RequestConfig) =>
  request.get<ResponseList<UserDetailDto>>({
    apiInfo: '我的信息',
    url: '/diet/app/user',
    ...config,
  });

/** 用户信息修改 */
export const postDietAppUserUpdate = (
  data: {
    /** 身高（厘米） */
    height: number;
    /** 体重（千克） */
    weight: number;
    /** 性别 */
    gender: 'MALE' | 'FEMALE' | 'OTHER';
    /** 出生日期
     * @format: date-time */
    birthDate: string;
    /** 总积分 */
    totalPoint?: number;
    /** 学历 */
    education: string;
    /** 合并症 */
    comorbidities?: string[];
    /** 密码（6-12位） */
    password: string;
    /** 手机号（登录账号） */
    phone: string;
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '用户信息修改',
    url: '/diet/app/user/update',
    data,
    ...config,
  });

/** 用户列表 */
export const getDietAdminUser = (
  query: {
    userId?: number;
    /** 手机号（登录账号） */
    phone?: string;
    /** 第几页 */
    pageNo?: number;
    /** 每页条数 */
    pageSize?: number;
  },
  config?: RequestConfig,
) =>
  request.get<ResponseList<AdminUserResDto>>({
    apiInfo: '用户列表',
    url: '/diet/admin/user',
    query,
    ...config,
  });

/** 用户登录,返回 token */
export const postDietAdminUserLogin = (
  data: {
    /** 验证码 */
    code: string;
    /** 手机号（登录账号） */
    phone: string;
    /** 密码（6-12位） */
    password: string;
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '用户登录,返回 token',
    url: '/diet/admin/user/login',
    data,
    ...config,
  });

/** 验证码 */
export const getDietAdminUserCaptcha = (config?: RequestConfig) =>
  request.get<ResponseList<string>>({
    apiInfo: '验证码',
    url: '/diet/admin/user/captcha',
    ...config,
  });

/** 创建事件 */
export const postDietAppAnalytics = (
  data: {
    /** 事件类型 */
    eventType?:
      | 'DIET_LOG'
      | 'NUTRITION_ANALYSIS'
      | 'NUTRITION_EDUCATION'
      | 'ANTI_INFLAMMATORY_RANKING'
      | 'PROFILE_VIEW'
      | 'VISIT'
      | 'CHECK_IN';
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '创建事件',
    url: '/diet/app/analytics',
    data,
    ...config,
  });

/** 事件总览 */
export const getDietAdminAnalytics = (config?: RequestConfig) =>
  request.get<ResponseList<AdminAnalyticsSummaryResDto>>({
    apiInfo: '事件总览',
    url: '/diet/admin/analytics',
    ...config,
  });

/** 食物列表 */
export const getDietAppFood = (
  data: {
    /** 食物分类 */
    category?: string;
  },
  config?: RequestConfig,
) =>
  request.get<ResponseList<FoodResDto[]>>({
    apiInfo: '食物列表',
    url: '/diet/app/food',
    data,
    ...config,
  });

/** 食物详情 */
export const getDietAppFoodFoodId = (foodId: number, config?: RequestConfig) =>
  request.get<ResponseList<FoodResDto>>({
    apiInfo: '食物详情',
    url: `/diet/app/food/${foodId}`,
    ...config,
  });

/** 食物列表 */
export const getDietAdminFood = (
  data: {
    /** 食物分类 */
    category?: string;
  },
  config?: RequestConfig,
) =>
  request.get<ResponseList<FoodResDto[]>>({
    apiInfo: '食物列表',
    url: '/diet/admin/food',
    data,
    ...config,
  });

/** 食物详情 */
export const getDietAdminFoodFoodId = (
  foodId: number,
  config?: RequestConfig,
) =>
  request.get<ResponseList<FoodResDto>>({
    apiInfo: '食物详情',
    url: `/diet/admin/food/${foodId}`,
    ...config,
  });

/** 食物修改 */
export const putDietAdminFoodFoodId = (
  foodId: string,
  data: {
    foodId?: number;
    /** 食物名称 */
    name?: string;
    /** 食物图片 */
    imageUrl?: string;
    /** 食物分类 */
    category?: string;
    /** 炎症指数 */
    rating?: number;
    /** 微量元素 */
    microElement?: unknown;
  },
  config?: RequestConfig,
) =>
  request.put<ResponseList<unknown>>({
    apiInfo: '食物修改',
    url: `/diet/admin/food/${foodId}`,
    data,
    ...config,
  });

/** 食物删除 */
export const deleteDietAdminFoodFoodId = (
  foodId: number,
  config?: RequestConfig,
) =>
  request.delete<ResponseList<unknown>>({
    apiInfo: '食物删除',
    url: `/diet/admin/food/${foodId}`,
    ...config,
  });

/** 积分列表 */
export const getDietAppPoint = (
  query: {
    /** 第几页 */
    pageNo?: number;
    /** 每页条数 */
    pageSize?: number;
  },
  config?: RequestConfig,
) =>
  request.get<ResponseList<AdminPointPageResDto>>({
    apiInfo: '积分列表',
    url: '/diet/app/point',
    query,
    ...config,
  });

/** 添加积分 */
export const postDietAppPoint = (
  data: {
    /** 积分数值 */
    count: number;
    /** 积分类型 */
    pointType: 'DAILY_CHECKIN' | 'MEAL_LOG' | 'CONTENT_SHARE';
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '添加积分',
    url: '/diet/app/point',
    data,
    ...config,
  });

/** 新建留言 */
export const postDietAppMessage = (
  data: {
    /** 内容 */
    content: string;
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '新建留言',
    url: '/diet/app/message',
    data,
    ...config,
  });

/** 留言列表 */
export const getDietAdminMessage = (
  query: {
    messageId?: number;
    /** 第几页 */
    pageNo?: number;
    /** 每页条数 */
    pageSize?: number;
  },
  config?: RequestConfig,
) =>
  request.get<ResponseList<AdminMessagePageResDto>>({
    apiInfo: '留言列表',
    url: '/diet/admin/message',
    query,
    ...config,
  });

/** 留言详情 */
export const getDietAdminMessageMessageId = (
  messageId: number,
  config?: RequestConfig,
) =>
  request.get<ResponseList<Message>>({
    apiInfo: '留言详情',
    url: `/diet/admin/message/${messageId}`,
    ...config,
  });

/** 删除留言 */
export const deleteDietAdminMessageMessageId = (
  messageId: number,
  config?: RequestConfig,
) =>
  request.delete<ResponseList<unknown>>({
    apiInfo: '删除留言',
    url: `/diet/admin/message/${messageId}`,
    ...config,
  });

/** 上传单个图片 */
export const postDietAdminUploadImage = (config?: RequestConfig) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '上传单个图片',
    url: '/diet/admin/upload/image',
    ...config,
  });

/** 上传多个图片 */
export const postDietAdminUploadImages = (config?: RequestConfig) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '上传多个图片',
    url: '/diet/admin/upload/images',
    ...config,
  });

/** 文章列表 */
export const getDietAppPost = (config?: RequestConfig) =>
  request.get<ResponseList<Post[]>>({
    apiInfo: '文章列表',
    url: '/diet/app/post',
    ...config,
  });

/** 文章详情 */
export const getDietAppPostPostId = (postId: number, config?: RequestConfig) =>
  request.get<ResponseList<Post>>({
    apiInfo: '文章详情',
    url: `/diet/app/post/${postId}`,
    ...config,
  });

/** 文章列表 */
export const getDietAdminPost = (
  query: {
    /** 文章标题 */
    title?: string;
    /** 文章ID */
    postId?: number;
    /** 第几页 */
    pageNo?: number;
    /** 每页条数 */
    pageSize?: number;
  },
  config?: RequestConfig,
) =>
  request.get<ResponseList<AdminPostResDto>>({
    apiInfo: '文章列表',
    url: '/diet/admin/post',
    query,
    ...config,
  });

/** 文章创建 */
export const postDietAdminPost = (
  data: {
    /** 文章标题 */
    title: string;
    /** 文章内容 */
    content: string;
    /** 文章图片 */
    image: string;
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '文章创建',
    url: '/diet/admin/post',
    data,
    ...config,
  });

/** 文章详情 */
export const getDietAdminPostPostId = (
  postId: number,
  config?: RequestConfig,
) =>
  request.get<ResponseList<Post>>({
    apiInfo: '文章详情',
    url: `/diet/admin/post/${postId}`,
    ...config,
  });

/** 文章删除 */
export const deleteDietAdminPostPostId = (
  postId: number,
  config?: RequestConfig,
) =>
  request.delete<ResponseList<unknown>>({
    apiInfo: '文章删除',
    url: `/diet/admin/post/${postId}`,
    ...config,
  });

/** 文章更新 */
export const patchDietAdminPostPostId = (
  postId: number,
  data: {
    /** 文章ID */
    postId: number;
    /** 文章标题 */
    title: string;
    /** 文章内容 */
    content: string;
    /** 文章图片 */
    image: string;
  },
  config?: RequestConfig,
) =>
  request.patch<ResponseList<unknown>>({
    apiInfo: '文章更新',
    url: `/diet/admin/post/${postId}`,
    data,
    ...config,
  });

/** 关联用户 */
export const postDietAppUserrelation = (
  data: {
    /** 关联目标用户ID */
    toUserId: number;
    /** 关联类型 */
    relationType?: 'SPOUSE' | 'PARENT' | 'CHILD' | 'SIBLING' | 'OTHER';
  },
  config?: RequestConfig,
) =>
  request.post<ResponseList<unknown>>({
    apiInfo: '关联用户',
    url: '/diet/app/user-relation',
    data,
    ...config,
  });

/** 关联用户查找 */
export const getDietAppUserrelationUserUserId = (config?: RequestConfig) =>
  request.get<ResponseList<UserRelation[]>>({
    apiInfo: '关联用户查找',
    url: '/diet/app/user-relation/user/{userId}',
    ...config,
  });

/** 关联用户更新 */
export const putDietAppUserrelationRelationId = (
  relationId: number,
  data: {
    /** 关联目标用户ID */
    toUserId?: number;
    /** 关联类型 */
    relationType?: 'SPOUSE' | 'PARENT' | 'CHILD' | 'SIBLING' | 'OTHER';
  },
  config?: RequestConfig,
) =>
  request.put<ResponseList<UserRelation>>({
    apiInfo: '关联用户更新',
    url: `/diet/app/user-relation/${relationId}`,
    data,
    ...config,
  });

/** 关联用户删除 */
export const deleteDietAppUserrelationRelationId = (
  relationId: number,
  config?: RequestConfig,
) =>
  request.delete<ResponseList<unknown>>({
    apiInfo: '关联用户删除',
    url: `/diet/app/user-relation/${relationId}`,
    ...config,
  });
